package com.example.myapplication;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

//折现
public class ZheView extends View {

    float x1 = 0, x2 = 0, x3 = 0, x4 = 0, x5 = 0, x6 = 0;
    float y1 = 0, y2 = 0, y3 = 0, y4 = 0, y5 = 0, y6 = 0;
    int width, height;

    public ZheView(Context context, int width, int height) {
        super(context);
        this.width = width;
        this.height = height;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(this.height, this.width);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Paint paint = new Paint();
        paint.setColor(Color.parseColor("#F44336"));

        Paint paintDot = new Paint();
        paintDot.setColor(Color.parseColor("#6200EE"));
        paintDot.setStrokeCap(Paint.Cap.ROUND);
        paintDot.setStrokeWidth(15);

        //画左边的
        //左眼
        if (x2 == 0 && y2 == 0) {
            canvas.drawLine(x1, y1, x3, y3, paint);
        } else {
            canvas.drawLine(x1, y1, x2, y2, paint);
            canvas.drawLine(x2, y2, x3, y3, paint);
        }
        canvas.drawPoint(x1, y1, paintDot);
        canvas.drawPoint(x2, y2, paintDot);
        canvas.drawPoint(x3, y3, paintDot);
        //右眼
//        if (x4 == 0 && y4 == 0) {
//            canvas.drawLine(x4, y4, x6, y6, paint);
//        } else {
//            canvas.drawLine(x4, y4, x5, y5, paint);
//            canvas.drawLine(x5, y5, x6, y6, paint);
//        }
//        canvas.drawPoint(x4, y4, paintDot);
//        canvas.drawPoint(x5, y5, paintDot);
//        canvas.drawPoint(x6, y6, paintDot);

        //画右边的
//        int screenWidth = MainActivity.widthPixels;
//        int wOffset = screenWidth - height;
//        //左眼
//        if (x2 == 0 && y2 == 0) {
//            canvas.drawLine(wOffset + x1, y1, wOffset + x3, y3, paint);
//        } else {
//            canvas.drawLine(wOffset + x1, y1, wOffset + x2, y2, paint);
//            canvas.drawLine(wOffset + x2, y2, wOffset + x3, y3, paint);
//        }
//        canvas.drawPoint(wOffset + x1, y1, paintDot);
//        canvas.drawPoint(wOffset + x2, y2, paintDot);
//        canvas.drawPoint(wOffset + x3, y3, paintDot);
//
//        //右眼
//        if (x4 == 0 && y4 == 0) {
//            canvas.drawLine(wOffset + x4, y4, wOffset + x6, y6, paint);
//        } else {
//            canvas.drawLine(wOffset + x4, y4, wOffset + x5, y5, paint);
//            canvas.drawLine(wOffset + x5, y5, wOffset + x6, y6, paint);
//        }
//        canvas.drawPoint(wOffset + x4, y4, paintDot);
//        canvas.drawPoint(wOffset + x5, y5, paintDot);
//        canvas.drawPoint(wOffset + x6, y6, paintDot);
    }

    public void setLine(float[] floats) {
        this.x1 = floats[1];
        this.y1 = 640 - floats[0];
        this.x2 = floats[3];
        this.y2 = 640 - floats[2];
        this.x3 = floats[5];
        this.y3 = 640 - floats[4];
//        this.x4 = floats[7];
//        this.y4 = 640 - floats[6];
//        this.x5 = floats[9];
//        this.y5 = 640 - floats[8];
//        this.x6 = floats[11];
//        this.y6 = 640 - floats[10];

        invalidate();
    }
}